package nameless.aistudy.common.exception;

import nameless.aistudy.common.enumeration.message.MessageEnum;
import org.springframework.http.HttpStatus;

public class BusinessException extends BaseException {
    private static final long serialVersionUID = 1L;

    private final HttpStatus status;
    public HttpStatus getStatus() {
        return this.status;
    }

    /* 通用业务异常 */
    public BusinessException() {
        super(MessageEnum.BAD_REQUEST.getMessage());
        this.status = HttpStatus.BAD_REQUEST;
    }

    public BusinessException(String message) {
        super(message);
        this.status = HttpStatus.BAD_REQUEST;
    }

    public BusinessException(HttpStatus status) {
        super(status.getReasonPhrase());
        this.status = status;
    }

    public BusinessException(HttpStatus status, String message) {
        super(message);
        this.status = status;
    }

    /* 404 Not Found (资源不存在) 异常 */
    public static BusinessException notFound() {
        return new BusinessException(HttpStatus.NOT_FOUND, MessageEnum.NOT_FOUND.getMessage());
    }

    public static BusinessException notFound(String message) {
        return new BusinessException(HttpStatus.NOT_FOUND, message);
    }

    /* 401 Unauthorized (未认证) */
    public static BusinessException unauthorized() {
        return new BusinessException(HttpStatus.UNAUTHORIZED, MessageEnum.UNAUTHORIZED.getMessage());
    }

    public static BusinessException unauthorized(String message) {
        return new BusinessException(HttpStatus.UNAUTHORIZED, message);
    }

    /* 403 Forbidden (无访问权限) */
    public static BusinessException forbidden() {
        return new BusinessException(HttpStatus.FORBIDDEN, MessageEnum.FORBIDDEN.getMessage());
    }

    public static BusinessException forbidden(String message) {
        return new BusinessException(HttpStatus.FORBIDDEN, message);
    }

}
